package com.example.administrator.zyfypt_211dsh.model;


import com.example.administrator.zyfypt_211dsh.bean.CollectionBean;
import com.example.administrator.zyfypt_211dsh.bean.TcaseBean;
import com.example.administrator.zyfypt_211dsh.iface.CollectionListener;
import com.example.administrator.zyfypt_211dsh.iface.Collectioniface;
import com.example.administrator.zyfypt_211dsh.service.CollectionService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Raindy on 2017/4/22.
 */

public class CollectionModel_tcase implements Collectioniface<TcaseBean> {
    private Retrofit retrofit;
    private String BASEURL="http://amicool.neusoft.edu.cn/";

    //构造方法
    public CollectionModel_tcase()
    {
        retrofit=new Retrofit.Builder()
                .baseUrl(BASEURL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }


    @Override
    public void getResultList(String mod, int page, String sessionID, final CollectionListener<TcaseBean> listener) {
        CollectionService collectionService = retrofit.create(CollectionService.class);
        Call<List<CollectionBean<TcaseBean>>> call = collectionService.getCTcaseList(mod,page,sessionID);
        call.enqueue(new Callback<List<CollectionBean<TcaseBean>>>() {
            @Override
            public void onResponse(Call<List<CollectionBean<TcaseBean>>> call, Response<List<CollectionBean<TcaseBean>>> response) {
                if (response.isSuccessful() && response.body()!=null)
                    listener.onResponse(response.body());
                else
                    listener.onFail("on response fall");
            }

            @Override
            public void onFailure(Call<List<CollectionBean<TcaseBean>>> call, Throwable t) {
                listener.onFail(t.toString());
            }
        });
    }
}
